﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using ZX.WebApp;
using ZX.BLL.Extend;
using ZX.SYS.Bussiness;
using ZX.EHR.Library;

using ZX.Common;
using ZX.DBModule;
using ZX.BLL.Extend;
using ZX.SYS.Library;
using ZX.BPM.Library;
using ZX.Web.UI.Controls;
using System.Text;


namespace ZX.WebApp.Crm.BasePages
{
    public partial class StartWorkflow1 : EditUIPage
	{
        string UserId = "";
        //string WorkflowId = "";
        //string WorktaskId = "";
        //string WorkflowInsId = "";
        //string WorktaskInsId = "";
        string title = "";//标题
        public string formTitle = "申请缴款单";
        ArrayList UserCtrlList = new ArrayList();//控件列表
        ZX.WebApp.CrmWorkFlowService.WorkFlowServiceClient workflow = new ZX.WebApp.CrmWorkFlowService.WorkFlowServiceClient();


        //2014_Affix
        public bool statue = false;
        //public string workinsid = "";
        public string worktasid = "";
        private string[] fieldList ={ "AffixId", "WorkflowId", "WorkflowInsId", "WorktaskId", "WorktaskInsId",
                                "FileNameId","FileName","FilePath"};
        //2014_Affix

        /// <summary>
        /// 表名
        /// </summary>
        public string TableName
        {
            get;
            set;
        }

        /// <summary>
        /// 流程ID
        /// </summary>
        public string WorkFlowId
        {
            get;
            set;
        }
        /// <summary>
        /// 流程务任ID
        /// </summary>
        public string WorkTaskId
        {
            get;
            set;
        }
        /// <summary>
        /// 表单类型
        /// </summary>
        public string FormType
        {
            get;
            set;
        }
        /// <summary>
        /// 页面标题
        /// </summary>
        public string PageTitle
        {
            get
            {
                return  Request["title"].ToString();
            }
        }

        public string IsIE
        {
            get
            {
                string isIE = "1";
                bool ise = UserPoint();
                isIE = (UserPoint()) ? "0" : "1";
                return isIE;
            }
        }
        /// <summary>
        /// 表单编号
        /// </summary>
        public string FormID{ get; set; }
        public string WorkFlowCaption { get; set; }
        public string EntityName { get; set; }

        public string WorkflowInsId { 
            get{

                string _WorkflowInsId = Session["workinsid"].ToString();
                if (_WorkflowInsId == "")
                {
                    _WorkflowInsId = Guid.NewGuid().ToString();
                }
                return _WorkflowInsId;
            } 
            set{
                Session["workinsid"] = value;
            } 
        
        }
        public string WorkTaskInsId { 
            get{
              
                 string _WorkTaskInsId = Session["WorkTaskInsId"].ToString();
                if (_WorkTaskInsId == "")
                {
                    _WorkTaskInsId = Guid.NewGuid().ToString();
                }
                return _WorkTaskInsId;
            } 
            set{
                Session["WorkTaskInsId"]=value;
            } 
        
        }
        public int PageIsPostBack {
            get {
                int isp = 0;
                if (IsPostBack) { isp = 1; }
                else { isp = 0; }
                return isp;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            UserId = this.Page.User.Identity.Name;
            try
            {
                if (this.Session["User"] == null)
                {
                    Response.Redirect("../../Login.aspx");
                }
                if (!IsPostBack)
                {
                    //string tableName = this.GetStringFromQueryString("entity", "");
                    //string keyValue = this.GetStringFromQueryString("keyValue", "");
                    //if (tableName != "" && keyValue != "")
                    //{
                    //    TableName = tableName;
                    //    KeyValue = keyValue;
                    //    if (Start(tableName, keyValue))
                    //    {
                    //        Response.Write("更新成功");
                    //        workflow.Start(UserId, WorkFlowId, WorkTaskId, WorkflowInsId, WorktaskInsId, workflow.GetWorkFlowNO(), "提交", "3", "缴款单", false);
                    //        Response.Redirect("tooltip.aspx?worktaskInstanceId=" + WorktaskInsId);
                    //    }
                    //    Response.Write("0");
                    //    return;
                    //}
                    // BaseUserPage.LoadWaitPage();
                    InitData();
                    WorkflowInsId = Guid.NewGuid().ToString();
                    WorkTaskInsId = Guid.NewGuid().ToString();
                    WorkTaskId = Request["WorktaskId"].ToString();
                    Session["worktasid"] = WorkTaskId;
                    CreateUI();
                    //InitAffixData();

                }
               
   

            }
            catch (Exception ex)
            {
                //LogData.WriteLog("平台打开启动界面错误:" + ex, lbWorkflowInsId.Text);

            }
            finally
            {
                if (!IsPostBack) { }
                //BaseUserPage.FreeWaitPage();
            }

        }
        private bool Start(string TableName, object KeyValue)
        {
            //ZX.SYS.Bussiness.WorkFlowStartInfo wfsi = new ZX.SYS.Bussiness.WorkFlowStartInfo();
            //return wfsi.Start(TableName, KeyValue);]
            return false;
        }
        public string URL
        {
            get;
            set;
        }
        private void InitData()
        {
            if (Request["WorkflowId"] != null && Request["WorktaskId"] != null)
            {
                WorkFlowId = Request["WorkflowId"].ToString();
                WorkTaskId = Request["WorktaskId"].ToString();
                WorkFlowCaption = "";
                title = Request["title"].ToString();
                DataTable cdt = workflow.GetWorkTaskFormsView(WorkTaskId);
                WorkFlowCaption = workflow.GetWorkFlowCaption(WorkFlowId);//Server.UrlEncode(workflow.GetWorkFlowCaption(WorkFlowId));
                if (cdt != null && cdt.Rows.Count > 0)
                {
                    FormType = cdt.Rows[0]["FormType"].ToString();

                    switch (FormType)
                    {
                        case "Html":
                            DataTable dt = workflow.GetTableEntity(cdt.Rows[0]["FilePath"].ToString());
                            EntityName = dt.Rows[0]["MasterTableName"].ToString();
                            FormID = dt.Rows[0]["FormID"].ToString();
                            TableName = EntityName;
                            //URL = "../../Extend/AutoLoadForm.aspx?entity=" + EntityName + "&action=insert&formid=" + FormID + "&workflowid=" + WorkFlowId + "&worktaskid=" + WorkTaskId + "&FlowCaption=" + WorkFlowCaption;    
                            break;
                        case "Page":
                            string url = cdt.Rows[0]["FilePath"].ToString().Replace('\\', '/');
                            url += "?flag=0&history=" + this.GetStringFromQueryString("history", "") + "&wtid=" + WorkTaskId + "&entity=" + cdt.Rows[0]["ChildCaption"].ToString() + "&title=" + title + "&wfid=" + WorkFlowId + "&FlowCaption=" + WorkFlowCaption;
                            //Server.Transfer("../" + url);
                            URL = "../" + url;
                            break;
                        case "URL":
                            URL = cdt.Rows[0]["FilePath"].ToString();
                            break;
                        default:
                            break;
                    }

                }

            }
        }

        //2014_Affix

        //private void InitAffixData()
        //{
        //    string guidvalue = string.Empty;

  
        //        statue = false;
        //        guidvalue =WorkflowInsId;
          
  
        //    DataTable dt = workflow.GetAffixTable(guidvalue, statue);
        //    if (dt.Rows.Count > 0)
        //    {
        //        gvAffixfiles.DataSource = dt;
        //        gvAffixfiles.DataBind();
        //    }
        //    else
        //    {
        //        gvAffixfiles.DataSource = null;
        //        gvAffixfiles.DataBind();
        //    }
        //    return;
        //}
        //protected void ButtonConfirm_Click(object sender, EventArgs e)
        //{
        //    //检查上传文件不为空
        //    if (inputFile.PostedFile.ContentLength <= 5242880 && inputFile.PostedFile.ContentLength > 0)
        //    {
        //        //设定上传文件的保存路径
        //        string strSaveDir = "../Files/";
        //        string strName = this.inputFile.PostedFile.FileName;
        //        //取得文件名(抱括路径)里最后一个"."的索引
        //        int intExt = strName.LastIndexOf(".");

        //        //取得文件扩展名
        //        string strExt = strName.Substring(intExt);
        //        //这里我自动根据日期和文件大小不同为文件命名,确保文件名不重复


        //        string filetype = strExt.Replace(".", "");
        //        filetype = filetype.ToUpper();
        //        if (filetype == "JS" || filetype == "EXE" || filetype == "MSI")
        //        {
        //            inputFile.Focus();
        //            labelUpResult.Text = "上传文件不能包脚文件与执行文件！";
        //            return;
        //        }
        //        else
        //        {
        //            //取得文件名(包括路径)里最后一个"\"的索引
        //            int intPath = strName.LastIndexOf("\\");
        //            //取得文件名(不包括路径)
        //            string strNewName = strName.Substring(intPath + 1);
        //            string filenameid = Guid.NewGuid().ToString();
        //            //保存文件到你所要的目录,这里是IIS根目录下的upload目录.你可以改变.
        //            //注意: 我这里用Server.MapPath()取当前文件的绝对目录.在asp.net里"\"必须用"\\"代替
        //            string filenamepath = Server.MapPath(strSaveDir + filenameid + strExt);
        //            this.inputFile.PostedFile.SaveAs(filenamepath);
        //            //得到这个文件的相关属性:文件名,文件类型,文件大小
        //            labelUpResult.Text = "上传成功！";
        //            //labelFileName.Text = "文件源：" + strName;
        //            //labelFileExt.Text = "文件类型：" + inputFile.PostedFile.ContentType + "( " + strExt + " )";
        //            //labelFileSize.Text = "文件大小：" + (inputFile.PostedFile.ContentLength / 1024).ToString() + " K Byte(s)";
        //            CrmWorkFlowService.AffixFiles entity = new CrmWorkFlowService.AffixFiles();
        //            entity.AffixId = filenameid;
        //            entity.WorkflowId = Request["WorkflowId"].ToString();

        //            entity.WorkflowInsId = WorkflowInsId;

        //            entity.WorktaskId = Request["WorktaskId"].ToString();
        //            entity.WorktaskInsId = WorkTaskInsId;//Convert.ToString(Session["worktasid"]);
        //            entity.FileNameId = filenameid + strExt;
        //            entity.FileName = strNewName;
        //            entity.FilePath = filenamepath;
        //            workflow.InsertAffixcrm(entity);
        //            labelUpResult.Text = "上传成功！";
        //            InitAffixData();
        //            return;
        //        }

        //    }
        //    else if (inputFile.PostedFile.ContentLength > 5242880)
        //    {
        //        labelUpResult.Text = "上传文件不能大于5M！";
        //        return;
        //    }
        //}
        //public static void OpenWindowInNewPage(Page curPage, string destUrl)
        //{
        //    string scriptString = string.Format("<script language='JavaScript'>window.open('" + "{0}" + "','_new','toolbar=no,resizable=yes,scrollbars=yes');<", destUrl);
        //    scriptString += "/";
        //    scriptString += "script>";
        //    if (!curPage.IsStartupScriptRegistered("Startup"))
        //    {
        //        curPage.RegisterStartupScript("Startup", scriptString);
        //    }
        //    return;
        //}
        //protected void lbtnFileName_Click(object sender, EventArgs e)
        //{
        //    string parms = (sender as LinkButton).CommandArgument.ToString();
        //    string name = (sender as LinkButton).CommandName.ToString();
        //    dFile(parms, name);
        //    return;
        //}
        //protected void LinkButton1_Click(object sender, EventArgs e)
        //{
        //    string parms = (sender as LinkButton).CommandArgument.ToString();
        //    string name = (sender as LinkButton).CommandName.ToString();
        //    dFile(parms, name);
        //    return;
        //}
        //protected void LinkButton2_Click(object sender, EventArgs e)
        //{

        //    BaseUserControl buc = new BaseUserControl();
        //    if (buc.CtrlState == WorkFlowConst.STATE_VIEW)
        //        return;
        //    string[] parms = (sender as LinkButton).CommandArgument.Split(',');
        //    int i = workflow.DeleteAffix(parms[0]);//删除数据库记录文件
        //    if (i > 0)
        //    {
        //        labelUpResult.Text = "删除成功！";
        //    }
        //    File.Delete(parms[1]);
        //    InitData();

        //}
        //protected void dFile(string parms, string name)
        //{
        //    //判断是否选择文件名
        //    if (parms != "")
        //    {
        //        //获取文件路径
        //        string path = Server.MapPath("../") + "Files\\" + parms;

        //        //初始化 FileInfo 类的实例，它作为文件路径的包装
        //        FileInfo fi = new FileInfo(path);
        //        //判断文件是否存在
        //        if (fi.Exists)
        //        {
        //            // ////将文件保存到本机上
        //            Response.Clear();
        //            Response.ClearContent();
        //            Response.ClearHeaders();
        //            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(name));
        //            Response.AddHeader("Content-Length", fi.Length.ToString());
        //            Response.AddHeader("Content-Transfer-Encoding", "binary");
        //            Response.ContentType = "application/octet-stream";
        //            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        //            Response.WriteFile(fi.FullName);
        //            Response.Flush();
        //            Response.End();


        //            ////以字符流的形式下载文件 
        //            //FileStream fs = new FileStream(path, FileMode.Open);

        //            //byte[] bytes = new byte[(int)fs.Length];

        //            //fs.Read(bytes, 0, bytes.Length);

        //            //fs.Close();
        //            //Response.Clear();
        //            //Response.ClearContent();
        //            //Response.ClearHeaders();
        //            //Response.AddHeader("Content-Length", bytes.Length.ToString());
        //            //Response.ContentType = "application/octet-stream";
        //            ////通知浏览器下载文件而不是打开 
        //            //Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(name, System.Text.Encoding.UTF8));
        //            ////Response.AddHeader("Content-Disposition", "attachment; filename=" + name);
        //            //Response.BinaryWrite(bytes);
        //            //Response.Flush();
        //            //Response.End();
        //        }
        //    }
        //    else
        //    {
        //        Page.RegisterStartupScript("sb1", "<script>alert('请先选择需要下载的文件，谢谢！')</script>");
        //    }
        //}
        //2014_Affix


        //2014_AutoLoadForm
        /// <summary>
        /// 流程状态
        /// </summary>
        public string Status
        {
            get;
            set;
        }




        public string FlowCaption
        {
            get;
            set;
        }
        /// <summary>
        /// 弹出列表客户经理ID
        /// </summary>
        public string addUser { get { return this.UserId.ToString(); } }

  

        BaseEntity MasterEntity = null;
        private void CreateUI()
        {
      

            string strEntity = EntityName;
            string action = "";
            string strFormID = FormID;
            string strWorkFlowId = WorkFlowId;
            string strWorkTaskId = WorkTaskId;
            FlowCaption = WorkFlowCaption;
            Status = "";
            string id ="";
            BaseEntity instance = ZX.Common.Globals.getEntity(strEntity) as BaseEntity;
            MasterEntity = instance;
            BaseBussnies bInstance = new BLL.Extend.BaseBussnies(instance);
            BaseEntity entity = null;
            string strDefaultPropertyValues = "";
            string WorkTaskFormRoles = "";
            string strWorkTaskTitle = "";
            if (instance == null)
            {
                instance = new DataTableBaseEntity();
                ((DataTableBaseEntity)instance).TableName = strEntity;
                string[] strArrary = ((DataTableBaseEntity)instance).GetKey();
                if (strArrary != null)
                {
                    ((DataTableBaseEntity)instance).TableKey = strArrary[0];
                    ((DataTableBaseEntity)instance).KeyType = strArrary[1];
                }
                ((DataTableBaseEntity)instance).CreateDT();
                //((DataTableBaseEntity)instance).EntityJson = ZX.Common.Globals.DataRowToJSON(((DataTableBaseEntity)instance).DRow);

                if (id != "") //有ID表示编辑
                {
                    entity = new DataTableBaseEntity(); //bInstance.GetEntityById(id) as BaseEntity;
                    ((DataTableBaseEntity)entity).TableName = strEntity;
                    ((DataTableBaseEntity)entity).TableKey = ((DataTableBaseEntity)instance).TableKey;
                    ((DataTableBaseEntity)entity).KeyType = ((DataTableBaseEntity)instance).KeyType;
                    ((DataTableBaseEntity)entity).CreateDT(id);
                    ((DataTableBaseEntity)entity).EntityJson = ZX.Common.Globals.DataRowToJSON(((DataTableBaseEntity)entity).DRow);
                    instance = entity;
                }
                else
                {
                    //初始化ID值
                    //KeyValue = instance.GetTableIdValue();
                    if (KeyValue == Guid.Empty.ToString() || String.IsNullOrEmpty(KeyValue))
                    {
                        ((DataTableBaseEntity)instance).DRow[((DataTableBaseEntity)instance).TableKey] = Guid.NewGuid();
                    }
                    ((DataTableBaseEntity)instance).EntityJson = ZX.Common.Globals.DataRowToJSON(((DataTableBaseEntity)instance).DRow);
                    KeyValue = instance.GetTableIdValue();
                    strDefaultPropertyValues = CreateDefaultPropertyValues();
                    strWorkTaskTitle = CreateWorkTaskTitle();
                }

                if (!string.IsNullOrEmpty(strWorkFlowId) && !string.IsNullOrEmpty(strWorkTaskId))
                {
                    WorkTaskFormRoles = CreateWorkTaskFormRoles(strWorkFlowId, strWorkTaskId, strFormID);
                }
            }
            else
            {
                //初始化ID值
                entity = bInstance.GetEntityById(id) as BaseEntity;
                if (entity != null)
                {
                    instance = entity;
                }
            }

            //获取
            if (instance != null)
            {
                object O = instance.GetKeyFieldValue();
                //object O = Globals.GetPropertyValue(instance, instance.GetTableId());
                Guid? _id = ((O) == null) ? null : O as Guid?;
                //初始化ID值
                if (_id == null || _id == Guid.Empty)
                {
                    Globals.SetPropertyValue(instance, instance.GetTableId(), Guid.NewGuid());
                }
            }
            if (!string.IsNullOrEmpty(strWorkFlowId) && !string.IsNullOrEmpty(strWorkTaskId))
            {
                WorkTaskFormRoles = CreateWorkTaskFormRoles(strWorkFlowId, strWorkTaskId, strFormID);
            }

            this.EditTemplate.Text = CreateHtml(instance, entity) + strDefaultPropertyValues + WorkTaskFormRoles + strWorkTaskTitle;
            KeyValue = instance.GetTableIdValue();
            //if (KeyValue == Guid.Empty.ToString())
            //{
            //    ((DataTableBaseEntity)instance).DRow[((DataTableBaseEntity)instance).TableKey] = Guid.NewGuid();
            //}
            //KeyValue =instance["ID"]; //instance.GetTableId();
            //用于定义相关数据绑定信息
            //用于定义相关数据绑定信息
            /////2012.5.8 汪定新修改------------------------------------------------
            string tempCondition = strFormID.Trim() == string.Empty || strFormID.Trim() == Guid.Empty.ToString() ? "FormID='" + strFormID + "' or MasterTableName='" + strEntity + "'" : "FormID='" + strFormID + "'";
            ZX.SYS.Library.SysCustomDefineForm FormEntity = bInstance.GetEntityByCondition<SysCustomDefineForm>(tempCondition);
            if (FormEntity.MasterTableName != strEntity)
            {
                FormEntity = bInstance.GetEntityByCondition<SysCustomDefineForm>("MasterTableName='" + strEntity + "'");
            }

            string tempCondition2 = strFormID.Trim() == string.Empty || strFormID.Trim() == Guid.Empty.ToString() ? "FormID='" + strFormID + "' or TableName='" + strEntity + "'" : "FormID='" + strFormID + "'";
            IList<ZX.SYS.Library.SysFieldItem> dsList = bInstance.GetEntitys<SysFieldItem>(tempCondition2);


            ///原来的
            //ZX.SYS.Library.SysCustomDefineForm FormEntity = bInstance.GetEntityByCondition<SysCustomDefineForm>("FormID='" + strFormID + "' or MasterTableName='" + strEntity + "'");
            //IList<ZX.SYS.Library.SysFieldItem> dsList = bInstance.GetEntitys<SysFieldItem>("FormID='" + strFormID + "' or TableName='" + strEntity + "'");
            ///------------------------------------------------------------------------------------
            //用于处理

            CreateUIData(dsList);
            if (FormEntity != null)
            {
                DetailsJson = FormEntity.DetailsJson;
                //Dictionary<string, string> _detail = ZX.Common.Globals.JSonToObject<Dictionary<string, string>>(DetailsJson);
                MasterEntity = instance;
                CreateDetailInstance(DetailsJson);
                FormTemplate.Text = FormEntity.HtmlString;
                this.jSave.Text = ""; //CreateScript(list);
            }
            //this.jInitControl.Text = "";// InitControl(list);
            this.MasterID.Text = SetMasterID();
        }

        /// <summary>
        /// 明细相关数据
        /// </summary>
        public string DetailData
        {
            get;
            set;
        }

        /// <summary>
        /// 不通过Ajax，直接生成明细数据，并返回
        /// </summary>
        public string DetailsListData
        {
            get;
            set;
        }


        private void CreateDetailInstance(string DetailsJson)
        {
            //DetailsJson = FormEntity.DetailsJson;
            if (!string.IsNullOrEmpty(DetailsJson))
            {
                IList<SysDetailsItem> list = ZX.Common.Globals.JSonToObject<IList<SysDetailsItem>>(DetailsJson);
                StringBuilder _details = new StringBuilder("");
                StringBuilder _detailsList = new StringBuilder("");
                foreach (var _detail in list)
                {
                    string table = _detail.DetailsTableName;
                    IList<ZX.SYS.Library.SysFieldItem> dsList = this._bll.GetEntitys<SysFieldItem>("TableName='" + table + "'");
                    DetailData = CreateUIData(dsList, false);
                    DataTableBaseEntity entity = new DataTableBaseEntity(); //bInstance.GetEntityById(id) as BaseEntity;
                    ((DataTableBaseEntity)entity).TableName = table;
                    string[] strArrary = ((DataTableBaseEntity)entity).GetKey();
                    if (strArrary != null)
                    {
                        ((DataTableBaseEntity)entity).TableKey = strArrary[0];
                        ((DataTableBaseEntity)entity).KeyType = strArrary[1];
                    }
                    entity.CreateDT();
                    IList<SysTableFKey> fkList = entity.GetFKey();
                    string _condtion = string.Empty;
                    if (fkList != null)
                    {
                        foreach (var e in fkList)
                        {
                            if (e.FKTableName == MasterEntity.GetTableName())
                            {
                                _condtion = _condtion == string.Empty ? e.FieldName + "='" + KeyValue + "'" : " and " + e.FieldName + "='" + KeyValue + "'";
                                FKExpression = FKExpression + e.FieldName + "='" + KeyValue + "'";
                                entity.SetFieldValue(entity, e.FieldName, KeyValue);
                            }
                        }
                    }
                    else
                    {
                        FKExpression = "1=0";
                    }

                    this._bll.entity = entity;
                    System.Data.DataTable dt = this._bll.GetDataBySqlComm(string.Format("select * from {0} where {1}", table, _condtion));
                    if (dt == null)
                    {
                        _detailsList.Append("var _" + table + "List=[];").AppendLine();
                    }
                    else
                    {
                        _detailsList.Append("var _" + table + "List=" + ZX.Common.Globals.Dtb2Json(dt) + ";").AppendLine();
                    }
                    ((DataTableBaseEntity)entity).EntityJson = ZX.Common.Globals.DataRowToJSON(((DataTableBaseEntity)entity).DRow);
                    _details.Append("var " + table + "=" + ((DataTableBaseEntity)entity).EntityJson + ";").AppendLine();
                    //_detailsList.Append("");

                }
                DetailsInstance = _details.ToString();
                DetailsListData = _detailsList.ToString();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string DetailsJson
        {
            get;
            set;
        }
        /// <summary>
        /// 明细表的实体
        /// </summary>
        public string DetailsInstance
        {
            get;
            set;
        }

        /// <summary>
        /// 外键表达式
        /// </summary>
        public string FKExpression
        {
            get;
            set;
        }

        /// <summary>
        /// 主键ID值
        /// </summary>
        public object MasterIDValue
        {
            get;
            set;
        }
        /// <summary>
        /// 行为参数
        /// </summary>
        public String Action
        {
            get
            {
                return this.GetStringFromQueryString("action", "");
            }

        }

        public String KeyValue
        {
            set;
            get;
        }
        /// <summary>
        /// 生成对应的下拉数据
        /// </summary>
        /// <param name="fieldList"></param>
        private void CreateUIData(IList<ZX.SYS.Library.SysFieldItem> fieldList)
        {
            this.jInitControl.Text = "";
            this.jInitControl.Text = CreateUIData(fieldList, true);
        }
        private string CrateUIData(IList<ZX.SYS.Library.SysFieldItem> fieldList, string TableName, bool IsMasterData)
        {
            return "";
        }


        /// <summary>
        /// 生成页面所需的常用数据，例如：下拉框所需的数据
        /// </summary>
        /// <param name="fieldList"></param>
        /// <param name="IsMasterData"></param>
        /// <returns></returns>
        private string CreateUIData(IList<ZX.SYS.Library.SysFieldItem> fieldList, bool IsMasterData)
        {
            if (fieldList == null)
            {
                return "";
            }
            StringBuilder strHtml = new StringBuilder("");
            foreach (var e in fieldList)
            {
                string _cFieldName = IsMasterData ? e.FieldName : "Detail_" + e.FieldName;
                IList<Dictionary> list = null;
                if (e.DataSourceType.ToLower() == "json")
                {
                    strHtml.Append("var ds_" + _cFieldName + "=" + e.DataSource + ";\r\n");
                    list = Globals.JSonToObject<IList<Dictionary>>(e.DataSource);
                    if (IsMasterData)
                    {
                        string str = "";
                        if (e.ControlsType == "select")
                        {
                            str = "$('#" + _cFieldName + "').comBind(ds_" + _cFieldName + ",\"ValueMember\",\"DisplayMember\");\r\n";
                        }
                        else
                        {
                            str = "createComboBox('" + _cFieldName + "', { itemSource: ds_" + _cFieldName + ", style: 'dropdown', autoComplete: 'local' });\r\n";
                        }
                        //string str= "$('#"+ e.FieldName+"').comBind(ds_"+e.FieldName+",\"ValueMember\",\"DisplayMember\");";
                        strHtml.Append(str);
                    }
                }
                if (e.DataSourceType.ToLower() == "sql")
                {
                    strHtml.Append("var ds_" + _cFieldName + "=");
                    BaseBussnies instance = new BaseBussnies();
                    list = instance.GetEntitysBySqlComm<Dictionary>(e.DataSource.Replace("[B]", "'"));
                    if (list != null)
                    {
                        strHtml.Append(Globals.ObjectToJSON(list) + ";");
                        if (IsMasterData)
                        {
                            string str = "";
                            if (e.ControlsType == "select")
                            {
                                str = "$('#" + _cFieldName + "').comBind(ds_" + _cFieldName + ",\"ValueMember\",\"DisplayMember\");\r\n";
                            }
                            else
                            {
                                str = "createComboBox('" + _cFieldName + "', { itemSource: ds_" + _cFieldName + ", style: 'dropdown', autoComplete: 'local' });\r\n";
                            }
                            //string str = "$('#" + e.FieldName + "').comBind(ds_" + e.FieldName + ",\"ValueMember\",\"DisplayMember\");\r\n";
                            strHtml.Append(str);
                        }
                    }
                    else
                    {
                        strHtml.Append("[];\r\n");
                    }

                }
                if (e.DataSourceType.ToLower() == "dic")
                {
                    strHtml.Append("var ds_" + _cFieldName + "=");
                    BaseBussnies instance = new BaseBussnies();
                    list = instance.GetEntitysBySqlComm<Dictionary>(string.Format("Exec [dbo].[sp_GetDicList] '{0}'", e.DataSource));
                    if (list != null)
                    {
                        strHtml.Append(Globals.ObjectToJSON(list) + ";\r\n");
                        if (IsMasterData)
                        {
                            string str = "";
                            if (e.ControlsType == "select")
                            {
                                str = "$('#" + _cFieldName + "').comBind(ds_" + _cFieldName + ",\"ValueMember\",\"DisplayMember\");\r\n";
                            }
                            else
                            {
                                str = "createComboBox('" + _cFieldName + "', { itemSource: ds_" + _cFieldName + ", style: 'dropdown', autoComplete: 'local' });\r\n";
                            }
                            strHtml.Append(str);
                        }

                    }
                    else
                    {
                        strHtml.Append("[];\r\n");
                    }
                }

                //return string.Format(strSControl, e.FieldName, strHtml.ToString(), width);
            }
            return strHtml.ToString();
        }
        private string CreateWorkTaskFormRoles(string xWorkFlowId, string xWorkTaskId, string xFormID)
        {
            string _formRoles = "";
            string _DetailsFormRoles = "";
            WorkTaskFormRoles fr = new WorkTaskFormRoles(xWorkFlowId, xWorkTaskId, xFormID);
            Hashtable ht = fr.DetailsPropertyValue;
            foreach (DictionaryEntry de in ht)
            {
                _DetailsFormRoles = "  var DetailsFormRoles=" + de.Value.ToString();
            }

            string _MasterFormRoles = " var MasterFormRoles=" + ZX.Common.Globals.ObjectToJSON(fr.MasterPropertyValue) + ";";
            // string _DetailsFormRoles = "  var DetailsFormRoles=" + 
            return _formRoles = _MasterFormRoles + _DetailsFormRoles;
        }


        private string CreateWorkTaskTitle()
        {
            string workTaskTitle = "";
            string _title = FlowCaption + "-" + this.EmpPropertyValues.Proposer + "-" + "[" + DateTime.Now.ToString("yyyy-MM-dd hh:ss:mm") + "]";
            workTaskTitle = "; var TaskTitle=\"" + _title + "\"";
            return workTaskTitle;
        }

        public string strWorkFlowId
        {
            get
            {
                return WorkFlowId;
            }
        }
        public string strWorkTaskId
        {
            get
            {
                return WorkTaskId;
            }
        }
        public string strOperatorInstanceId
        {
            get
            {      
                string oid = Guid.NewGuid().ToString();
              
                return oid;
            }
        }
        public string strWorkflowInsId
        {
            get
            {
                return WorkflowInsId;
            }
        }
        public string strWorkTaskInsId
        {
            get
            {
                return WorkTaskInsId;
            }
        }
        //2014_AutoLoadForm
	}
}